package beans;
import java.util.HashMap;
import java.util.Map.Entry;
import org.hibernate.*;
import domain.ExpressShipPath;
/**
 * ExpressShipPathQuery 
 */
public class ExpressShipPathQuery extends AbstractPagedQuery<ExpressShipPath> {
	/**
	 * 起始城市 
	 */
	private String startPos;
	/**
	 * 目的城市 
	 */
	private String endPos;
	/**
	 * 服务类型 
	 */
	private String serviceType;
	/**
	 * 运输方式 
	 */
	private String transPortType;
	/**
	 * 构建hibernate Query对象.需要构造查询sql语句,并将查询参数设置到Query对象中.
	 * @param pSession hibernate session
	 * @param pIsQueryTotalCount 是否是构造查询纪录总数目的Query.
	 * @return hibernate Query
	 */
	public Query buildQuery(Session pSession, boolean pIsQueryTotalCount) {
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		if (pIsQueryTotalCount) {// 查询总数
		    sql.append("select count(*) from ExpressShipPath t where 1=1 ");
		} else {
	    	sql.append(" from ExpressShipPath t where 1=1 ");
	    }
	    	if (null != startPos) {
	        queryParams.put("startPos", "%"+startPos+"%");
	        sql.append(" and t.startPos like:startPos ");
	    }
	    	if (null != endPos) {
	        queryParams.put("endPos", "%"+endPos+"%");
	        sql.append(" and t.endPos like:endPos ");
	    }
	    	if (null != serviceType) {
	        queryParams.put("serviceType", "%"+serviceType+"%");
	        sql.append(" and t.serviceType like:serviceType ");
	    }
	    	if (null != transPortType) {
	        queryParams.put("transPortType", "%"+transPortType+"%");
	        sql.append(" and t.transPortType like:transPortType ");
	    }
	    Query query = pSession.createQuery(sql.toString());
	    for (Entry<String, Object> entry : queryParams.entrySet()) {
	        query.setParameter(entry.getKey(), queryParams.get(entry.getKey()));
	    }
	    return query;
	}
	/**
	 * @return String 
	 */
	public String getStartPos(){
		return startPos;
	}
	/**
	 * @param pStartPos 
	 */
	public void setStartPos(String pStartPos){
		startPos=pStartPos;
	}
	/**
	 * @return String 
	 */
	public String getEndPos(){
		return endPos;
	}
	/**
	 * @param pEndPos 
	 */
	public void setEndPos(String pEndPos){
		endPos=pEndPos;
	}
	/**
	 * @return String 
	 */
	public String getServiceType(){
		return serviceType;
	}
	/**
	 * @param pServiceType 
	 */
	public void setServiceType(String pServiceType){
		serviceType=pServiceType;
	}
	/**
	 * @return String 
	 */
	public String getTransPortType(){
		return transPortType;
	}
	/**
	 * @param pTransPortType 
	 */
	public void setTransPortType(String pTransPortType){
		transPortType=pTransPortType;
	}
}
